//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "tyr_fnccontainer\updateHandler.sqf"
#include <core_macros.h>

TRACE_1("Start",_this);

private ["_handler","_handler_id","_idx","_array","_handlers_list","_functions_list"];
_handler = toupper(_this select 0);
_handler_id = toupper(_this select 1);
_function = _this select 2;

if (typename _handler_id != typename 0) exitWith { false };

if (TYR_FUNCTIONS_IS_BUSY) exitWith {
	_this spawn {
		TRACE("Wait");
		waituntil {!TYR_FUNCTIONS_IS_BUSY};
		_this call tyr_fnc_updateHandler;
	};
};
TYR_FUNCTIONS_IS_BUSY = true;

_handlers_list = TYR_FUNCTIONS_HANDLER_LIST select 0;
_functions_list = TYR_FUNCTIONS_HANDLER_LIST select 1;

_idx = _handlers_list find _handler;
if (_idx >= 0) then {
	_handlers = _functions_list select _idx;
	if (_handler_id < count _handlers) then {
		_handlers set [_handler_id, _function];
		_functions_list set [_idx,_handlers];
		TYR_FUNCTIONS_HANDLER_LIST = [_handlers_list,_functions_list];
	};
};
TYR_FUNCTIONS_IS_BUSY = false;
TRACE("End");